package com.example.mq;

import com.example.mq.clients.Consumer1;
import com.example.mq.clients.Producer1;
import com.example.mq.server.BrokerServer;
import com.example.mq.server.consumermanager.ConsumerEnv;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import javax.print.attribute.standard.ColorSupported;
import java.io.IOException;

@SpringBootApplication
public class MqApplication {

    // 添加一个静态成员，方便后续取bean
    public static ConfigurableApplicationContext context;

    public static void main(String[] args) throws IOException, InterruptedException {
        context = SpringApplication.run(MqApplication.class, args);

        // 启动服务器
        BrokerServer brokerServer = new BrokerServer(9090);
        brokerServer.start();

    }

}

// 启动生产者客户端
class Producer1Main {
    public static void main(String[] args) throws IOException {
        Producer1 producer1 = new Producer1("127.0.0.1", 9090);
        producer1.start();
    }
}

// 启动消费者客户端
class Consumer1Main {
    public static void main(String[] args) throws IOException, InterruptedException {
        Consumer1 consumer1 = new Consumer1("127.0.0.1", 9090);
        consumer1.setReadResponse(true);
        consumer1.start();

    }
}
